// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import VueRouter from 'vue-router';
import routes from '@/router';
import ElementUI from 'element-ui';
import Mixin from './mixins';
import axios from 'axios';
import 'element-ui/lib/theme-chalk/index.css';
import VueCookies from 'vue-cookies';
import store from '@/store';

Vue.use(VueCookies)
Vue.config.productionTip = false
Vue.use(VueRouter);
Vue.use(ElementUI);
Vue.mixin(Mixin);
const router = new VueRouter({
  routes,
});
// ajax
Vue.$http = Vue.prototype.$http = axios.create({
  baseURL: 'http://mogen.dmxiaoshuo.cn',
  // baseURL: 'http://mogen.i6bktq.cn:83',
  // baseURL: 'http://api.i6bktq.cn:83',
  withCredentials: true,// `withCredentials` 表示跨域请求时是否需要使用凭证
  timeout: 300000
});
Vue.prototype.$http.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  // console.log(response.status);
  return response;
}, function (error) {
  if (error.response) {
      if (error.response.status == 403) {
          router.push({path: '/'});
      }
  }
  return Promise.reject(error);
});
// POST传参序列化
// Vue.prototype.$http.interceptors.request.use((config) => {
//     // if (config.method === 'POST' || config.method === 'post') {
//     //     config.headers.Authorization = 'Bearer ' + getNowCookie().token;
//     // }
//     return config;
// }, (error) => {
//     return Promise.reject(error);
// });
//  
/* eslint-disable no-new */
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app');
